#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
"""
@UserFor     :   ***    ***
@File        :   meddle_213_打家劫舍2.py    
@Email       :   18574945291@163.com
@Modify Time :   2021-02-15 18:20
@Author      :   code_wizard (wll)

这个和原版打家劫舍最大的问题是  列表是环壮结构

"""

class Solution:
    def rob(self, nums):
        def my_rob(nums):
            dp1, dp2 = 0, 0
            for num in nums:
                dp2, dp1 = max(dp1 + num, dp2), dp2
            return dp2

        return max(my_rob(nums[:-1]), my_rob(nums[1:])) if len(nums) != 1 else nums[0]



if __name__ == '__main__':
    nums = [2, 3, 2]
    obj = Solution()
    print(obj.rob(nums))